package com.rbac.shiro;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import com.rbac.bean.Permission;
import com.rbac.dao.PermissionDao;

public class FilterChainDefinitionMapBuilder {
	
	@Autowired
	private PermissionDao permissionDao;
	
	public Map<String,String> buildFilterChainDefinitionMap(){
		LinkedHashMap<String,String> map=new LinkedHashMap<>();
		map.put("/bootstrap/**", "anon");
		map.put("/css/**", "anon");
		map.put("/fonts/**", "anon");
		map.put("/img/**", "anon");
		map.put("/jquery/**", "anon");
		map.put("/layer/**", "anon");
		map.put("/script/**", "anon");
		map.put("/ztree/**", "anon");
		
		
		map.put("/login.jsp", "anon");
		map.put("/login", "anon");
		map.put("/logout", "logout");
//		map.put("/user.jsp", "authc,roles[user]");
//		map.put("/admin.jsp", "authc,roles[admin]");
//		map.put("/list.jsp", "user");
		List<Permission> perms = permissionDao.queryAll();
		for(Permission permission : perms) {
			if(StringUtils.hasText(permission.getUrl())) {
				map.put(permission.getUrl(),String.format( "perms[%s]", permission.getUrl()));
			}			
		}
		
		
		map.put("/**", "user");
		
		return map;
	}

}
